/* 
 * File:   MessageRecord.h
 * Author: liuyi
 *
 * Created on July 21, 2009, 2:28 PM
 */

#ifndef _MESSAGE_H
#define	_MESSAGE_H

#include <string>
#include <sstream>
#include <iostream>

using namespace std;

class Log {
public:
    enum TYPE {NON, INFO, WARN, ERROR };

    static void log(string message, TYPE type = NON);

    Log & append(const char* str) {
        m_ss << str;
        return *this;
    }
    Log & append(bool b) {
        m_ss << b;
        return *this;
    }
    Log & append(char c) {
        m_ss << c;
        return *this;
    }
    Log & append(int i) {
        m_ss << i;
        return *this;
    }
    Log & append(long l) {
        m_ss << l;
        return *this;
    }
    Log & append(float f) {
        m_ss << f;
        return *this;
    }
    Log & append(double d) {
        m_ss << d;
        return *this;
    }
    
    void printBuffer(TYPE type = NON) {
        log(m_ss.str(), type);
        clearBuffer();
    }
    void clearBuffer() {
        m_ss.str("");
    }

    Log() {
        m_ss.str("");
    }
    ~Log() { }
    
private:
    stringstream m_ss;
    
};

#endif	/* _MESSAGERECORD_H */

